package com.biz.primus.common.support.jackson;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import java.io.IOException;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;

/**
 * PrimusLocalDateTime2EpochMillisDeserializer
 *
 * 使用系统的时区转换milliseconds到Java8 LocalDateTime
 *
 * @author david-liu
 */
public class PrimusLocalDateTime2EpochMillisDeserializer extends JsonDeserializer<LocalDateTime> {
    @Override
    public LocalDateTime deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
        return Instant.ofEpochMilli(Long.parseLong(p.getText())).atZone(ZoneId.systemDefault()).toLocalDateTime();
    }
}
